var Index = require('../app/controllers/index');
var Menu = require('../app/controllers/menu');
var ContentType = require('../app/controllers/contenttype');
var Content = require('../app/controllers/content');
var menuService = require('../app/services/menuService');
var Base = require('../app/controllers/base');

module.exports = function(app){
	app.use(async function(req,res,next){
		if(req.query.pjax){
			res.locals.layout="../pjax_layout.html";
			next();
		}else{
			var data = await menuService.GetAllList(req,res)
			res.locals.layout="../default_layout.html";
			res.locals.parentMenus = data;
			next();
		}
	});
	app.post('/apply/upload',Base.upload);
	app.get('/',Index.index);
	/**
	 * qiniu
	 */
	app.get('/info',Base.info);
	
	app.get('/qiniu',Base.getqiniu);

	app.post('/qiniu',Base.postqiniu);
	/**
	 * 菜单管理
	 */
	/**
	 * 页面部分
	 */
	app.get('/menu',Menu.menu);
	app.get('/menu/add',Menu.add);
	app.get('/menu/:id',Menu.add);

	app.get('/api/menu',Menu.menus);
	app.post('/api/menu',Menu.create);
	app.put('/api/menu/:id',Menu.update);
	app.delete('/api/menu',Menu.delete);
	/**
	 * 内容类别管理
	 */
	app.get('/contenttype',ContentType.contenttype);
	app.get('/contenttype/add',ContentType.add);
	app.get('/contenttype/:id',ContentType.add);

	app.get('/api/contenttype',ContentType.contenttypes);
	app.post('/api/contenttype',ContentType.create);
	app.put('/api/contenttype/:id',ContentType.update);
	app.delete('/api/contenttype',ContentType.delete);
	/**
	 * 内容管理
	 */
	app.get('/content',Content.content);
	app.get('/content/add',Content.add);
	app.get('/content/:id',Content.add);

	app.get('/api/content',Content.contents);
	app.post('/api/content',Content.create);
	app.put('/api/content/:id',Content.update);
	app.delete('/api/content',Content.delete);
}